#include "stdafx.h"
#include "TextTriangle.h"

#define PI 3.14159265


TextTriangle::TextTriangle(float X1, float Y1, float X2, float Y2, float X3, float Y3, float TextX, float TextY , float size, char * str) :Triangle(X1, Y1, X2, Y2, X3, Y3), Text(TextX, TextY, size, str)
{
}


TextTriangle::~TextTriangle()
{
}
void TextTriangle::debugPrint()
{
	std::cout << "Text in Triangle (" << x1 << " , " << y1 << ") (" << x2 << " , " << y2 << ") (" << x3 << " , " << y3 << ")" << "\ntext (" << x << "," << y << ")" << " Text = '" << this->text_p << "' size = " << this->size << std::endl;
}
void TextTriangle::moveShape(float new_x, float new_y)
{
	x1 += new_x; y1 += new_y;
	x2 += new_x; y2 += new_y;
	x3 += new_x; y3 += new_y;
	x += new_x; y += new_y;
}
void TextTriangle::rotateShape(float angle)
{
	float Xmid, Ymid;
	Xmid = (x2 - x1) / 2;
	Ymid = (y3 - y1) / 2;

	x1 = Xmid + (x1 + Xmid)*cos(angle*PI / 180) + (y1 - Ymid)*sin(angle*PI / 180);
	y1 = (x1 - Xmid)*sin(angle*PI / 180) - Ymid + (y1 - Ymid)*cos(angle*PI / 180);

	x2 = Xmid + (x2 - Xmid)*cos(angle*PI / 180) + (y2 - Ymid)*sin(angle*PI / 180);
	y2 = Ymid + (x2 - Xmid)*sin(angle*PI / 180) + (y2 - Ymid)*cos(angle*PI / 180);

	x3 = (x3 - Xmid)*cos(angle*PI / 180) - Xmid + (y3 - Ymid)*sin(angle*PI / 180);
	y3 = (x3 - Xmid)*sin(angle*PI / 180) - Ymid + (y3 - Ymid)*cos(angle*PI / 180);
}
void TextTriangle::zoomShape(float zoom)
{
	float Xmid = 0, Ymid = 0;

	Xmid = x2 - x1;
	Ymid = y3 - y1;

	x1 = x1 - ((Xmid - x1)*(zoom - 1));
	x2 = x2 + ((x2 - Xmid)*(zoom - 1));

	y1 = y1 - ((Ymid - y1)*(zoom - 1));
	y2 = y1;
	y3 = y3 + ((y3 - Ymid)*(zoom - 1));

	size *= zoom;
}